from time import sleep

from gpiozero import AngularServo, LED

led = LED(17)


def feed(length: float):
    s = AngularServo(
        "WPI6",
        initial_angle=0,
        min_angle=0,
        max_angle=180,
        min_pulse_width=0.000544,
        max_pulse_width=0.0024,
        frame_width=20 / 1000
    )

    led.on()
    s.angle = 90
    sleep(length)
    s.angle = 0
    sleep(0.4)
    s.detach()
    led.off()


def init(angle=0):
    led.blink(
        n=3,
        on_time=0.2,
        off_time=0.2
    )

    s = AngularServo(
        "WPI6",
        initial_angle=0,
        min_angle=0,
        max_angle=180,
        min_pulse_width=0.000544,
        max_pulse_width=0.0024,
        frame_width=20 / 1000
    )
    s.angle = angle
    sleep(1)
    s.detach()
